<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>我要提现</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="/statics/layui/css/layui.css" media="all">
  <style>
  .layui-elem-quote{
      border-left: 5px solid #3b85c8;
    }
    </style>
</head>

<body>
  <blockquote class="layui-elem-quote">
    1、您当前提现币种 <span id="tipTypeId" style="color:green">A</span> 不能超过余额 <span id="tipMoney" style="color:red">1000</span>！
    <br />
    2、提现手续费 <span id="tipCashBrokePercent" style="color:red">0</span>% ，
    手续费最低 <span id="tipCashBrokeMin" style="color:green">0</span>，
    手续费上限 <span id="tipCashBrokeMax" style="color:red">0</span>！<br />
    3、提现最低数量 <span id="tipCashMin" style="color:red">1</span>！
  </blockquote>
  <br />
  <form class="layui-form" action="">
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label"><span class="layui-required">*</span> 提现数量</label>
        <div class="layui-input-inline" style="width: 100px;">
          <input type="text" id="money" name="money" lay-filter="money" lay-verify="required|number" placeholder="￥"
            autocomplete="off" class="layui-input" />
        </div>
        <div class="layui-form-mid layui-word-aux">
          实际到账：<span id="tipRealMoney" style="color:green">0</span>&nbsp;&nbsp;&nbsp;
          手续费：<span id="tipBrokeMoney" style="color:red">0</span>
        </div>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label"><span class="layui-required">*</span> 接币地址</label>
        <div class="layui-input-inline" style="width: 330px;">
          <input type="text" id="moneyAddress" name="moneyAddress" lay-verify="required" placeholder="接币地址"
            autocomplete="off" class="layui-input" maxlength="100">
        </div>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label"><span class="layui-required">*</span> 交易密码</label>
        <div class="layui-input-inline" style="width: 150px;">
          <input type="password" id="dealPassword" name="dealPassword" lay-verify="required|pass" placeholder="请输入交易密码"
            autocomplete="off" class="layui-input" maxlength="6" />
        </div>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label"><span class="layui-required">*</span> 手机验证码</label>
        <div class="layui-input-inline" style="width: 180px;">
          <input id="smsCode" type="text" name="smsCode" lay-verify="required|number" placeholder="请输入6位手机验证码"
            autocomplete="off" class="layui-input" maxlength="6" />
        </div>
        <div class="layui-input-inline" style="width: 150px;">
          <button id="btn_sms" class="layui-btn layui-btn-normal">获取</button>
        </div>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-input-block">
        <br />
        <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="demo1">立即提交</button>
      </div>
    </div>
  </form>
  <script src="/statics/layui/layui.js" charset="utf-8"></script>
  <script type="text/javascript" src="../js/jquery-1.11.0.min.js"></script>
  <script type="text/javascript" src="../js/config.js"></script>
  <script type="text/javascript" src="../js/utils.js"></script>

  <script>
    var id = "", model = null, lock = false;
    $(function () {
      id = Utils.getUrlParam("id");
      if (!id) {
        window.location.href = "../usercenter.html";
        return;
      }
      getMoneyInfo(id, function () {
        layui.use(['form'], function () {
          var form = layui.form, layer = layui.layer;

          //自定义验证规则
          form.verify({
            pass: [/(.+){6,12}$/, '密码必须6到12位']
          });

          //算出手续费和实际到账数量
          $("#money").on('change', function () {
            var m1 = $("#money").val();
            if (ValidateUtils.isFloat(m1)) {
              m1 = parseFloat(m1);
              if (m1 < model.moneyType.cashMin) {
                $("#tipBrokeMoney").text(0);
                $("#tipRealMoney").text(0);
                layer.alert('提现数量最低 ' + model.moneyType.cashMin + ' ' + model.typeName + '！', { title: '出错了', icon: 5 }, function (index) {
                  $("#money").val('');
                  $("#money").focus();
                  layer.close(index);
                });
                return false;
              }
              var max = parseFloat($("#tipMoney").text());
              if (m1 > max) {
                layer.alert("提现数量不能超过 " + max, { title: '出错了', icon: 5 }, function (index) {
                  $("#money").val('');
                  $("#money").focus();
                  layer.close(index);
                });
                return false;
              }
              var brokeMoney = FormatUtils.formatFloat2(m1 * model.moneyType.cashBrokePercent / 100);
              if (brokeMoney < model.moneyType.cashBrokeMin) {
                brokeMoney = model.moneyType.cashBrokeMin;
              } else if (model.moneyType.cashBrokeMax > 0 && brokeMoney > model.moneyType.cashBrokeMax) {
                brokeMoney = model.moneyType.cashBrokeMax;
              }
              $("#tipBrokeMoney").text(brokeMoney);
              $("#tipRealMoney").text(FormatUtils.formatFloat2(m1 - brokeMoney));
            } else {
              layer.alert('请输入整数或者小数！', { title: '出错了', icon: 5 }, function (index) {
                $("#money").val('');
                $("#money").focus();
                layer.close(index);
              });
            }
          });

          //获取手机验证码
          $("#btn_sms").on('click', function () {
            if (lock) return false;

            //开始倒计时
            $("#btn_sms").addClass("layui-btn-disabled");
            lock = true;
            time = 120;
            t = setInterval(function () {
              time--;
              $("#btn_sms").text(time + '(s)');
              if (time <= 0) {
                $("#btn_sms").removeClass("layui-btn-disabled");
                $("#btn_sms").text("获取");
                lock = false;
                clearInterval(t);
              }
            }, 1000);

            var url = Config.WEB_SERVER_API + Config.URI.USER_SMS_SEND;
            HttpUtils.httpPost(url, {}, function (result, success) {
              if (success) {
                layer.alert('短信验证码已发送到您的手机，请注意查收！', { title: '提示' });
              } else {
                layer.alert(result.resultMsg, { title: '出错了', icon: 5 });
                $("#btn_sms").removeClass("layui-btn-disabled");
                lock = false;
                t = null;
              }
            });
            return false;
          });

          //监听提交
          form.on('submit(demo1)', function (data) {
            var json = data.field;
            json.money = parseFloat(json.money);
            json.brokeMoney = parseFloat($("#tipBrokeMonoey").text());
            json.realMoney = parseFloat($("#tipRealMonoey").text());
            json.typeId = model.typeId;
            var typeName = $("#tipTypeId").text();
            layer.confirm('确定要提现 ' + json.money + ' (' + typeName + ') 吗?', { icon: 3, title: '提示' }, function (index) {
              var url = Config.WEB_SERVER_API + Config.URI.USER_MONEY_CASH_SAVE;
              HttpUtils.httpPost(url, json, function (result, success) {
                if (success) {
                  layer.alert('请记住订单号：<span color="red">' + result.resultMsg + '</span>', { title: '提交成功' }, function (index) {
                    window.parent.location.reload();
                  });
                } else {
                  layer.alert(result.resultMsg, { title: '出错了', icon: 5 });
                }
              });
              layer.close(index);
            });
            return false;
          });

          //表单初始赋值
          // form.val('example', {"money":100});
        });
      });
    });

    var getMoneyInfo = function (id, callback) {
      DataUtils.getUserMoneyInfo(id, function (data) {
        if (!data) {
          window.top.location.href = "index.html?t=" + new Date().getTime();
          return;
        }
        model = data;
        $("#tipTypeId").text(data.typeName);
        $("#tipMoney").text(data.money);
        if (data.moneyType) {
          $("#tipCashMin").text(data.moneyType.cashMin + " " + data.typeName);
          $("#tipCashBrokePercent").text(data.moneyType.cashBrokePercent);
          $("#tipCashBrokeMin").text(data.moneyType.cashBrokeMin);
          $("#tipCashBrokeMax").text(data.moneyType.cashBrokeMax);
        }
        if (callback) {
          callback();
        }
      });
    };


  </script>

</body>

</html>